package fashionshop.dal;

import java.sql.ResultSet;

import database.MySQLConnect;
import fashionshop.bll.LevelBLL;

public class LevelDAL {

	public LevelDAL(){
	}
	
	public static ResultSet LoadAll() throws Exception{
		MySQLConnect conn = new MySQLConnect();
		String sqlQuery = "SELECT * FROM level";
		return conn.executeQuery(sqlQuery);
	}

	public static int Update(LevelBLL level) throws Exception{
		MySQLConnect conn = new MySQLConnect();
		String sql = "UPDATE level SET `Name`='%s', `DiscountPercent`='%d', `Score`='%d' WHERE `ID`='%d'";
		String sqlQuery = String.format(sql, level.getName(), level.getDiscountPercent(), level.getScore(), level.getId());
		return conn.executeUpdate(sqlQuery);
	}
	
	public static ResultSet LoadIDByName(String name) throws Exception{
		MySQLConnect conn = new MySQLConnect();
		String sql = "SELECT ID FROM level WHERE Name = '%s'";
		String sqlQuery = String.format(sql, name);
		return conn.executeQuery(sqlQuery);
	}
	
}
